/*****************************************************************************************
**  Author:jxx 2022
**  QQ:283591387
**完整文档见：http://v2.volcore.xyz/document/api 【代码生成页面ViewGrid】
**常用示例见：http://v2.volcore.xyz/document/vueDev
**后台操作见：http://v2.volcore.xyz/document/netCoreDev
*****************************************************************************************/
//此js文件是用来自定义扩展业务代码，可以扩展一些自定义页面或者重新配置生成的代码
import modelHeader from "../goodsin_class/goodsInCom.vue"
let extension = {
  components: {
    //查询界面扩展组件
    gridHeader: modelHeader,
    gridBody: '',
    gridFooter: '',
    //新建、编辑弹出框扩展组件
    modelHeader: modelHeader,
    modelBody: '',
    modelFooter: ''
  },
  tableAction: '', //指定某张表的权限(这里填写表名,默认不用填写)
  buttons: { view: [], box: [], detail: [] }, //扩展的按钮
  watch: {

  },
  methods: {
    //下面这些方法可以保留也可以删除
    onInit() {  //框架初始化配置前，
      this.detailOptions.textInline = false
    },
    onInited() {
      let selectUrl = `api/q_goods_inventory/getPageData`
      let paramArr = []
      this.buttons.push({  
        name: '有库存', 
        type: 'success',
        onClick: function () {
          paramArr = []
          let searchObj = {
            name: null,
            value: null,
            displayType: null,
          }
          if (this.searchFormFields.goods_Storage_Location) {
            searchObj.name = "goods_Storage_Location"
            searchObj.value = this.searchFormFields.goods_Storage_Location
            searchObj.displayType = "select"
            paramArr.push(searchObj)
          } else if (this.searchFormFields.goods_code) {
            searchObj.name = "goods_code"
            searchObj.value = this.searchFormFields.goods_code
            searchObj.displayType = "text"
            paramArr.push(searchObj)
          }
          this.http.post(selectUrl, { page: 1, rows: 30, sort: "goods_code", order: "desc", wheres: JSON.stringify(paramArr) }, "").then(reslut => {
            this.$refs.table.rowData = reslut.rows.filter(item => item.goods_inventory_quantity)
          })

        }
      }); this.buttons.push({ 
        name: '无库存', 
        type: 'info', 
        onClick: function () {
          paramArr = []
          let searchObj = {
            name: null,
            value: null,
            displayType: null,
          }
          if (this.searchFormFields.goods_Storage_Location) {
            searchObj.name = "goods_Storage_Location"
            searchObj.value = this.searchFormFields.goods_Storage_Location
            searchObj.displayType = "select"
            paramArr.push(searchObj)
          } else if (this.searchFormFields.goods_code) {
            searchObj.name = "goods_code"
            searchObj.value = this.searchFormFields.goods_code
            searchObj.displayType = "text"
            paramArr.push(searchObj)
          }
          this.http.post(selectUrl, { page: 1, rows: 30, sort: "goods_code", order: "desc", wheres: JSON.stringify(paramArr) }, "").then(reslut => {
            this.$refs.table.rowData = reslut.rows.filter(item => !item.goods_inventory_quantity)
          })
        }
      });
      this.buttons.splice(this.buttons.findIndex(item=>item.name=="高级查询"),1)
      //框架初始化配置后
      //如果要配置明细表,在此方法操作
      //this.detailOptions.columns.forEach(column=>{ });
      this.setFiexdSearchForm(true);
      setTimeout(() => {
        this.searchFormOptions.forEach(x => {
          x.forEach(item => {
            if (item.field == "goods_code") {
              item.extra = {
                icon: "el-icon-zoom-in",
                text: "选择商品",
                style: "color:#3a8ee6;font-size:13px;padding-right: 20px;letter-spacing: 8px;cursor: default;",
                click: () => {
                  this.$refs.gridHeader.detailOpen()
                }
              }
            }
          })
        })
      }, 0)
      if (this.$route.path != "/q_goods_inventory") {
        this.height = 550 - 150;
        this.buttons.forEach(item => {
          if (item.value != "Search" && item.value != undefined) {
            item.hidden = true
          }
        })
        this.detailOptions.buttons = []
        //设置默认查询
      }
    },
    searchBefore(param) {
      //界面查询前,可以给param.wheres添加查询参数
      //返回false，则不会执行查询
      if(this.$route.path != "/q_goods_inventory"){
        param.wheres = param.wheres.filter(item => item.name != "ID")
        this.$route.query={}
      }
      return true;
    },
    async searchAfter(rows, result) {
      //查询后，result返回的查询数据,可以在显示到表格前处理表格的值
      return true;
    },
    addBefore(formData) {
      //新建保存前formData为对象，包括明细表，可以给给表单设置值，自己输出看formData的值
      return true;
    },
    updateBefore(formData) {
      //编辑保存前formData为对象，包括明细表、删除行的Id
      return true;
    },
    rowClick({ row, column, event }) {
      //查询界面点击行事件
      this.$refs.table.$refs.table.toggleRowSelection(row);
    },
    modelOpenAfter(row) {
      //点击编辑、新建按钮弹出框后，可以在此处写逻辑，如，从后台获取数据
      //(1)判断是编辑还是新建操作： this.currentAction=='Add';
      //(2)给弹出框设置默认值
      //(3)this.editFormFields.字段='xxx';
      //如果需要给下拉框设置默认值，请遍历this.editFormOptions找到字段配置对应data属性的key值
      //看不懂就把输出看：console.log(this.editFormOptions)
    }
  }
};
export default extension;
